﻿@using SmartStore.Admin.Models.Themes
@model ConfigureThemeModel

@{    
    ViewBag.Title = string.Format(T("Admin.Configuration.Themes.Title"), Model.ThemeName);
	string parsingError = (string)TempData["SassParsingError"];
}

@using (Html.BeginForm())
{
	<div class="multi-store-scope well px-0 py-2">
		<table class="adminContent adminContent-boxed">
		<tr>
			<td class="adminTitle">
				@Html.SmartLabelFor(model => model.StoreId)
			</td>
			<td class="adminData">
				@Html.DropDownList("StoreId", Model.AvailableStores, new { onchange = "location.href = '" + ViewData["ConfigureThemeUrl"] + "&storeId=' + this.value;" })
			</td>
		</tr>
		</table>
	</div>

    <div class="section-header">
        <div class="title">
            <i class="fa fa-paint-brush"></i>
            @ViewBag.Title @Html.ActionLink("(" + T("Admin.Common.BackToList") + ")", "List", new { storeId = Model.StoreId })
        </div>
        <div class="options">
			@{ Html.RenderWidget("admin_button_toolbar_before"); }

            <button type="submit" name="save" value="save" class="btn btn-warning">
                <i class="fa fa-check"></i>
                <span>@T("Admin.Common.Save")</span>
            </button>
            <button type="submit" name="save" value="save-continue" class="btn btn-secondary">
                <span>@T("Admin.Common.SaveContinue")</span>
            </button>
            <a href="#importvariables-window" data-toggle="modal" class="btn btn-secondary">
                <i class="far fa-arrow-alt-circle-up"></i>
                <span>@T("Common.Import")</span>
            </a>
            <a href="#exportvariables-window" data-toggle="modal" class="btn btn-secondary">
                <i class="far fa-arrow-alt-circle-down"></i>
                <span>@T("Common.Export")</span>
            </a>
            <a href='@Url.Action("Reset", new { theme = Model.ThemeName, storeId = Model.StoreId })' id="reset-vars" class="btn btn-danger">
                <i class="far fa-trash-alt"></i>
                <span>@T("Admin.Common.Reset")</span>
            </a>

			@{ Html.RenderWidget("admin_button_toolbar_after"); }
        </div>
    </div>

	if (parsingError.HasValue())
	{
		<div class="mb-5">
			<h4 class="text-danger">@T("Admin.Configuration.Themes.Validation.ErrorReportTitle")</h4>
			<pre>@parsingError</pre>
			<a class="btn btn-danger" href='@Url.Action("Configure", new { theme = Model.ThemeName, storeId = Model.StoreId })'>
				@T("Admin.Configuration.Themes.Validation.RestorePrevValues")
			</a>	
		</div>
	}

	<div class="theme-editor">
		@{ Html.RenderAction("ConfigureTheme", "Theme", new { theme = Model.ThemeName, storeId = Model.StoreId, area = (string)null }); }
	</div>
}

@*import variables window*@
@{Html.SmartStore().Window()
    .Name("importvariables-window")
    .Title(T("Admin.Configuration.Themes.ImportVars"))
    .Content(
    @<text>
		<form enctype="multipart/form-data" method="POST" action="@Url.Action("ImportVariables", "Theme", new { theme = Model.ThemeName, storeId = Model.StoreId })">
            <p class="text-muted">
                @T("Admin.Configuration.Themes.ImportVars.Note")
            </p>
            <div>
                @T("Admin.Configuration.Themes.ImportVars.XmlFile"): <input type="file" id="importxmlfile" name="importxmlfile" />
            </div>
        </form>
    </text>)
    .FooterContent(
    @<text>
        <button type="button" class="btn btn-secondary btn-flat" data-dismiss="modal">
			<span>@T("Admin.Common.Cancel")</span>
		</button>
        <button id="importxmlsubmit" type="button" class="btn btn-primary">
			<span>@T("Common.Import")</span>
		</button>
    </text>)
    .Render();
}

@*export variables window*@
@{Html.SmartStore().Window()
    .Name("exportvariables-window")
    .Title(T("Admin.Configuration.Themes.ExportVars"))
    .Content(
    @<text>
		<form enctype="multipart/form-data" method="POST" action="@Url.Action("ExportVariables", "Theme", new { theme = Model.ThemeName, storeId = Model.StoreId })">
            <p class="text-muted">
                @T("Admin.Configuration.Themes.ExportVars.Note")
            </p>
            <div class="form-group">
                <label>@T("Admin.Configuration.Themes.ExportVars.ProfileName") </label>
				@Html.TextBox("exportprofilename", "", new { placeholder = T("Common.Optional") })
            </div>
        </form>
    </text>)
    .FooterContent(
    @<text>
        <button type="button" class="btn btn-secondary btn-flat" data-dismiss="modal">
			<span>@T("Admin.Common.Cancel")</span>
		</button>
        <button id="exportxmlsubmit" type="button" class="btn btn-primary">
			<span>@T("Common.Export")</span>
		</button>
    </text>)
    .Render();
}

<script>
    $(function () {

        // import
        $('#importxmlsubmit').on('click', function (e) {
            e.preventDefault();
            $('#importvariables-window').find("form").submit();
        });

        // export
        $('#exportxmlsubmit').on('click', function (e) {
            e.preventDefault();
            $('#exportvariables-window').find("form").submit();
			$('#exportvariables-window').modal('hide');
        });

    });
</script>
